<?php //pack11class

class TablePropertiesPopup extends Module {

    public $width="400px";
    public $traceEnabled=true;
    public $cancel="Cancel";
    public $question="Undefined";
    public $submit="Submit";
    public $buttons="";

    public function setup() {
        $this->question=LabelManager::getLabel("table_properties_label");
        $this->setID("TablePropertiesPopup");
        $this->setClass("popup");
        $form=new TablePropertiesForm;
        $form->setID("TablePropertiesForm");
        $queryObject=GetQuery::useDefinedVars();
        $form->action="?state=".GetQuery::generate($queryObject);
        //trace("TablePropertiesAction: ".GetQuery::$qline);
        Tracer::showAllVars();
        if(array_key_exists("search", $_GET)) $form->action.="&search";

        $spacer=new Spacer;
        $spacer->addStyle("height","14px");
        $form->addChild($spacer);

        $form->addChild($this->generateCurrencySelect());
        $spacer->addStyle("height","6px");
        $form->addChild($spacer);
        $form->addChild($this->generatePriceCheck());

        $cancel=new FormButton;
        $cancel->value=LabelManager::getLabel("button_cancel");
        $cancel->type=FormButton::TYPE_BUTTON;
        $cancel->setID("TablePropertiesCancel");
        $form->addButton($cancel);

        $save=new FormButton;
        $save->value=LabelManager::getLabel("button_save");
        $save->type=FormButton::TYPE_BUTTON;
        $save->setID("TablePropertiesSubmit");
        $form->addButton($save);

        $this->buttons=$form->getButtons();
        $this->addChild($form);

    }

    private function generateCurrencySelect() {
        $select=new SelectInput;
        $currencies=CurrencyManager::getCurrencies();
        if(!$currencies) {
            return false;
        }
        foreach($currencies as $currency) {
            $option=new SelectOption;
            $option->label=$currency->label;
            $option->value=$currency->id;
            $option->selected=($currency==CurrencyManager::currentCurrency())? SelectOption::SELECTED:"";
            $select->addChild($option);
        }

        $select->label=LabelManager::getLabel("search_currency_label");
        $select->property_name="currency";
        $select->setID("TablePropertiesForm_currency");
        $select->events=str_replace('\"', '"', "onChange=\"TablePropertiesPopup.setCurrency(this);\"");
        $select->class="select_horisontal";
        $select->setLeftPosition(50);
        $select->addStyle("width","100px");
        $select->addStyle("color","#000000");
        $select->addStyle("position","relative");
        $select->addStyle("margin-left","20px");
        $select->lamp_class="hidden";
        return $select;
    }

    private function generatePriceCheck() {
        $item=new CheckBoxInput;
        $item->property_name="showPrice";
        $item->setID("TablePropertiesForm_showPrice");
        $item->label=LabelManager::getLabel("showPrice_checkbox_label");
        $item->checked=(ObjectsManager::$showPrice)? CheckBoxInput::CHECKED:"";
        $item->value=(ObjectsManager::$showPrice)? "1":"0";
        $item->formid="TablePropertiesForm";
        $item->events=str_replace('\"', '"', "onChange=\"TablePropertiesPopup.setShowPrice(this);\"");
        $item->addStyle("margin-left","20px");
        $item->setClass("TablePropertiesShowPrice");
        return $item;
    }

}
?>
